<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<title>传输加解密</title>
	<script src="js/utils/hex.js"></script>
	<script src="js/utils/byteUtil.js"></script>
	<script src="js/crypto/sm3-1.0.js"></script>
	<script src="js/utils/jquery-3.3.1.min.js"></script>

	<script src="js/ext/jsbn.js"></script>
	<script src="js/ext/jsbn2.js"></script>
	<script src="js/ext/ec.js"></script>
	<script src="js/ext/ec-patch.js"></script>
	<script src="js/ext/prng4.js"></script>
	<script src="js/ext/rng.js"></script>
	<script src="js/crypto/sm2-2.0.js"></script>
	<script src="js/crypto/sm4-1.0.js"></script>
	<script src="js/gm.js"></script>
	<!--jquery依赖-->

	<style>
		body {
			text-align: center
		}

		.div {
			margin: 0 auto;
			border: 1px solid #F00
		}
	</style>
</head>

<body>
	<div style="text-align:center;">
		<div>
			<form action="#" method="post">
				<table style="margin-left: auto;margin-right: auto;">
					<!--border=0 cellpadding=0 cellspacing=0-->
					<tr>
						<td style="width:auto;text-align: right;">
							输入数据：
						</td>
						<td style="text-align: left;" valign="middle">
							<textarea rows="5" cols="50" name="inputtext" id="inputtext"></textarea>
						</td>
					</tr>
					<tr>
						<td style="width:auto;text-align: right;">
							结果：
						</td>
						<td style="text-align: left;" valign="middle">
							<textarea rows="5" cols="50" name="crypttext" id="crypttext"></textarea>
						</td>
					</tr>
					<tr>
						<td colspan="2" style="width:auto;text-align: center;">
							<input type="button" value="加密" id="btn_enc" />
							<input type="button" value="解密" id="btn_dec" />
						</td>
					</tr>
				</table>

			</form>
		</div>
	</div>
	<script>
		/*
		 * 测试加密
		 */
		$("#btn_enc").click(function () {
			var inputtext = $("#inputtext").val();
			if (inputtext.length <= 0) {
				alert("输入数据不能为空");
			}
			var cipher = gmTransmissionEncrypt(inputtext)
			$("#crypttext").val(cipher);
		});

		/*
		 * 测试解密
		 */
		$("#btn_dec").click(function () {
			var inputtext = $("#inputtext").val();
			if (inputtext.length <= 0) {
				alert("输入数据不能为空");
			}
			var plain = gmTransmissionDecrypt(inputtext)
			$("#crypttext").val(plain);
		});
	</script>
</body>

</html>